import {fileURLToPath, URL} from 'node:url'

import {ConfigEnv, defineConfig, loadEnv,} from 'vite'
import vue from '@vitejs/plugin-vue'

const env = loadEnv("development", process.cwd())

// https://vitejs.dev/config/
export default defineConfig((conf: ConfigEnv) => {
    const env = loadEnv(conf.mode, process.cwd());
    console.log(env)
    return {
        server: {
            host: '0.0.0.0',
            proxy: {
                '/api': {
                    target: env.VITE_URL,
                    changeOrigin: true,
                    ws: true,
                    rewrite: (path) => path.replace(/^\/api/, "")
                }
            }
        },
        plugins: [
            vue(),
        ],
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url))
            }
        }
    }
})
